package me.send.data.service.provider;

import java.util.Map;
import me.send.business.base.SendVariable;
import me.send.data.service.pojo.User;

public class UserProvider {
    public String list_page(Map<String, Object> parameter) {
	// 获取 对象 查询对象 2015年6月23日17:34:01
	User user = (User) parameter.get(SendVariable.DATA);
	// 判断下面的字段 是否是null
	String sql = "select * from user where 1=1 ";
	if (user != null) {
	    if (user.getNickname() != null
		&& !user.getNickname().equals("")) {
		sql += " and nickname like '%" + user.getNickname()
		       + "%' ";
	    }
	    if (user.getSex() > 0) {
		sql += " and sex = " + user.getSex() + " ";
	    }
	    if (user.getStatus() > 0) {
		sql += " and status = " + user.getStatus() + "";
	    }
	}
	sql += " limit #{PAGE.start},#{PAGE.rows} ";
	return sql;
    }
    
    public String count(Map<String, Object> parameter) {
	// 获取 对象 查询对象 2015年6月23日17:34:01
	User user = (User) parameter.get(SendVariable.DATA);
	// 判断下面的字段 是否是null
	String sql = "select count(1) as total from user where 1=1 ";
	if (user != null) {
	    if (user.getNickname() != null
		&& !user.getNickname().equals("")) {
		sql += " and nickname like '%" + user.getNickname()
		       + "%'";
	    }
	    if (user.getSex() > 0) {
		sql += " and sex = " + user.getSex() + " ";
	    }
	    if (user.getStatus() > 0) {
		sql += " and status = " + user.getStatus() + "";
	    }
	}
	return sql;
    }
    
    public String batch_delete(Map<String, Object> parameter) {
	String userids = (String) parameter.get("userids");
	String sql = "";
	if (userids != null && !userids.equals("")) {
	    sql = "delete from user where userid in (" + userids + ")";
	}
	return sql;
    }
}
